package site.xuxingcan.xposedxiwang;

import java.io.*;
import java.net.Socket;

/**
 * Created by mengniu on 16-6-27.
 */
public class SocketHelper {
    private BufferedWriter os;
    private BufferedReader is;

    public SocketHelper(Socket socket) throws IOException {
        os = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
        is = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
    }

    public void writeLineAndFlush(String s) {
        try {
            if (!s.endsWith("\n")) {
                s = s + "\n";
            }
            os.write(s);
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String readLine() throws IOException {
        return is.readLine();
    }
}